<?php

class Default_UsersController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
        $session = new Zend_Session_Namespace('customers');
        if(!isset($session->u))
        {
        	$this->_redirect('/index/login');
        }
        
        $ajaxContext = $this->_helper->getHelper('AjaxContext');
        $ajaxContext->addActionContext('like', 'json')
                    ->addActionContext('dislike', 'json')->initContext();
    }

    public function indexAction()
    {
        
    }

    public function favoriteAction()
    {
        $session = new Zend_Session_Namespace('customers');
        if(isset($session->like) and !empty($session->like))
        {
        	$product = new Default_Model_Product();
        	$result = $product->id($session->like)->toArray();
        	$this->view->like = $result;
        }
        
    }

    public function likeAction()
    {
        $id = $this->_request->getParam('id');
        $session = new Zend_Session_Namespace('customers');
        $session->u->like($id);
        $session->like[]=$id;
        $this->_helper->viewRenderer->setNoRender(true);
        $this->_helper->layout()->disableLayout();
    }

    public function dislikeAction()
    {
        $id = $this->_request->getParam('id');
        $session = new Zend_Session_Namespace('customers');
        $session->u->dislike($id);
        $session->like = array_diff($session->like, array($id));
        $this->_helper->viewRenderer->setNoRender(true);
        $this->_helper->layout()->disableLayout();
    }

    public function historyAction()
    {
        $session = new Zend_Session_Namespace('customers');
        $this->view->history = $session->u->history(); 
    }

    public function detailOrderAction()
    {
        $id = $this->_request->getParam('id');
        $session = new Zend_Session_Namespace('customers');
        $result = $session->u->order($id);
        
        if(!empty($result))
        {
            
            $this->view->order = $result[0];
            $this->view->items = $result[1];
        }
        //$this->_helper->viewRenderer->setNoRender(true);
        
    }


}











